![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
waseem1345
Hello, I'm new to C language, and I'm using Visual C as my compiler..
Here's my code:
Code:
#include <stdio.h>#include <stdlib.h>
#include <Windows.h>
int i[8][8];
void main(){
int row;
int col;
for(row=0;row<=7;row++)
{
for(col=0;col<=7;col++)
{
i[row][col]=0;
}
}
printi();
getchar();getchar();
}
int printi()
{
char s[500];
int row;
int col;
int g;
int a=0;
for ( row=0; row < 7; row++ )
{
for ( col=0; col < 7; col++ )
{
s[a]=("%c", (char)i[row][col] );
a++;
}
}
for(g=0;g<=sizeof(s);g++)
{
int a=0;
if(a<8){
printf("%c",s[g]);
printf(" ");
}
else{
a=0;
printf("\n");
}
}
return 0;
}
I want it to give this output:
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
But it gives me a weird set of characters that are not letters or numbers.. only weird symbols.. can u fix the code for me please and explain the problem?
Thanks in advance
![Big Grin](https://cboard.cprogramming.com/images/smilies/biggrin.png)
Erm, not really sure what you're trying to do. but if you're goal is to just display a bunch of 0's (8 across, 8 deep), your code is a little confusing.
I adjusted your code slightly, you should be able to see the difference.
Code:
#include <stdio.h>
#include <stdlib.h>
void printi(int row, int col, int i[row][col]);
int main()
{
int i[8][8];
int row;
int col;
for(row = 0; row < 8; row++)
{
for(col = 0; col < 8; col++)
{
i[row][col] = 0;
}
}
printi(row, col, i);
return 0;
}
void printi(int row, int col, int i[row][col])
{
for (row = 0; row < 8; row++ )
{
for (col = 0; col < 8; col++)
{
printf("%d", i[row][col]);
}
printf("\n");
}
}
if this doesn't answer your question, let me know.
Also, a little note for you, if you're using visual studio, use 'start without debugging' and you won't need to add 'getchar()' to stop the window from closing